{extend name="base/base" /}
{block name="style"}
<style type="text/css">

</style>
{/block}
{block name="content"}

        <table id="table" lay-filter="table"></table> 
         <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
      </script>

{/block}
{block name="script"}
<script>
layui.use('table', function(){
  var table = layui.table; 
  table.render({
  elem: '#table'
  ,height: 'full-150'
  ,url: '/admin/system/dataList/' //数据接口
  ,limit:20
  ,page: true //开启分页
  ,cols: [[ //表头
    {field:'discription', title: '参数名', width: 500}
    ,{field:'val', title: '参数值', width:300}
     ,{title:'操作', toolbar: '#barDemo', width:200}
    ]]
  });
    //监听工具条
  table.on('tool(table)', function(obj){
    var data = obj.data;
    if(obj.event === 'edit'){
      layer.prompt({
      formType: 3,
        value: data.val,
        title: data.discription
      }, function(value,index){
        var post_data = {
          id:data.id,
          val:value
        };
        $.ajax({
          url:'/admin/system/editVal',
          type:'POST',
          data:post_data,
          success:function(ret){
            if (ret.code == 0) {
              layer.msg('修改成功');
              $(".layui-laypage-btn")[0].click();
            } else {
              layer.msg(ret.msg);
            }
          }
        }); 
      });
    }
  }); 
  // ///监听单元格编辑
  // table.on('edit(table)', function(obj){
  //   var value = obj.value //得到修改后的值
  //   ,data = obj.data //得到所在行所有键值
  //   ,field = obj.field; //得到字段
  //   var post_data = {
  //     id:data.id,
  //     val:value
  //   };
  //   $.ajax({
  //           url:"{:url('admin/system/editVal')}",
  //           type:"POST",
  //           data:post_data,
  //           success:function(ret){
  //               if (ret.code == 1) {
  //                 layer.msg('操作成功');
  //                 $(".layui-laypage-btn")[0].click();
  //               }
  //               if (ret.code == 0) {
  //                   layer.msg(ret.msg);
  //               }
  //           }
  //       });
  // });

});
</script>
{/block}
